<?php
require('../config.php');
require('auth/auth.php');

?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
      <link rel="stylesheet" href="../dist/css/font-awesome-4.5.0/css/font-awesome.min.css">

      <!-- Ionicons -->
    <link rel="stylesheet" href="../plugins/ionicons-2.0.1/ionicons-2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="../plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="../../admin_self/plugins/bootstrap-daterangepicker-master/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <style>
        .date { position: relative;margin-bottom: 20px }
        .date i {
        position: absolute; bottom: 10px; right: 24px; top: auto; cursor: pointer;
        }
        div.changePassDiv {
            position: absolute;
            margin: auto;
            top: -5%;
            left: 0;
            bottom: 0;
            right: 0;
            width: 25%;
            height: 100px;
            background: rgba(211, 211, 211, 0.9);
            z-index:9999;
            display: none;
        }

    </style>
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">

      <?php require('common/nav.html');?>
      <?php if($_GET['p']=='dashboard'){require('dashboard/dashboard.html');}?>
      <?php if($_GET['p']=='cpaSearch'){require('user/cpaSearch.html');}?>
  </div>
    <!-- jQuery 2.1.4 -->
    <script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../bootstrap/js/bootstrap.min.js"></script>
  <!-- DataTables -->
    <script src="../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../plugins/datatables/dataTables.bootstrap.min.js"></script
    <!-- jQuery Knob Chart -->
    <script src="../plugins/knob/jquery.knob.js"></script>
    <!-- datepicker -->
    <script src="../../admin_self/plugins/bootstrap-daterangepicker-master/moment.js"></script>
    <script src="../../admin_self/plugins/bootstrap-daterangepicker-master/daterangepicker.js"></script>
    <!-- Slimscroll -->
    <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../dist/js/demo.js"></script>
  <!-- page script -->
  <script>
      $(function () {
          Init();

          $('#date-range_picker').daterangepicker({
              startDate:initTime,
              endDate:initTime,
              locale: {
                  format: 'YYYY-MM-DD'
              },
          }, function(start, end) {
              startTime = start.format('YYYY-MM-DD');
              endTime = end.format('YYYY-MM-DD');
              getDataList(startTime, endTime);
          });
          getDataList();
      });
      //查询条件
      var startTime,endTime,productName;
      var page=1,number=10;
      //初始化时间
      var date = new Date();
      var initTime = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+(date.getDate()-1);
      function Init(){
          $('#data-search').on('change',function(){
              productName = $('#data-search').val();
              getDataList(startTime,endTime,productName);
          });
          $('.pagination li:last a').on('click',function(){
              pageMani(1);
              getDataList(startTime,endTime,productName);

          });
          $('.pagination li:first a').on('click',function(){
              pageMani(0);
              getDataList(startTime,endTime,productName);

          });
      }
      function emptyDataTable(){
          $('#dateTable').empty();
      }
      function getDataList(startTime, endTime, productName){
          emptyDataTable();
          $.ajax({
              url: 'api/data.php',
              type: 'GET',
              dataType: 'json',
              data: {
                  'startTime' : startTime?startTime:initTime,
                  'endTime' : endTime?endTime:initTime,
                  'productName' : productName?productName:'',
                  'page' : page,
                  'number' : number
              }
              })
              .done(function(rs) {
                  var string2;
                  var count = rs.count;
                  var num = rs.num;

                  var string1 =  "<thead><tr>"+
                      "<th>日期</th>"+
                      "<th>产品名称</th>"+
                      "<th>渠道名称</th>";
                          if(rs.data[0].active_user_ck == -1){
                              string1 += "<th>新增用户</th>"+
                                         "<th>激活用户</th>"+
                                         "<th>信息费</th>";
                          }else{
                              string1 += "<th id='active_user'>激活用户</th>";
                          }
                      string1+="</tr>"+
                      "</thead>"+
                      "<tbody id='dateTable'>";

                  var string3 = "</tbody>";

                  for(var i in rs.data ){

                      string2 += "<tr>"+
                          "<td>"+rs.data[i].time+"</td>"+
                          "<td>"+rs.data[i].product_name+"</td>"+
                          "<td>"+rs.data[i].pipe_name+"</td>";
                              if(rs.data[i].active_user_ck == -1){
                                  string2 += "<td>"+rs.data[i].new_user_number+"</td>"+
                                  "<td>"+rs.data[i].active_user+"</td>"+
                                  "<td>"+Math.round(rs.data[i].money_display)+"</td>";
                              }else{
                                  string2 += "<td>"+rs.data[i].active_user_ck+"</td>";
                              }
                      string2 += "<tr>";


                  }
                  $('#example2').html(string1+string2+string3);

                  $('#active_user').html('激活用户（总计：'+num+'）');
                  $('#num').html('查询数据：'+count+'条');

                  if(page==1&&count <= page * number){
                      $('.pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page==1&&count > page * number){
                      $('.pagination li:last a').removeClass('disabled');
                      $('.pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page>1&&count <= page * number){
                      $('.pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.pagination li:first a').removeClass('disabled');
                  }else if(page>1&&count > page * number){
                      $('.pagination li:last a').removeClass('disabled');
                      $('.pagination li:first a').removeClass('disabled');
                  }else if(page<1){
                      pageMani();
                      $('.pagination li:last a').removeClass('disabled').addClass('btn');
                      $('.pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }
              })
              .fail(function() {
                  console.log("error");
              })
              .always(function() {
                  console.log("complete");
              })

      }
      function loginOut(){
          $.ajax({
                  url: 'api/user.php',
                  type: 'GET',
                  data: {
                      'action' : 'loginOut',
                      'loginOut' : 1,
                  }
              })
              .done(function(data){
                 if(data == 1){
                     window.location.href = "http://139.224.34.168/admin_user/modules/auth/login.php";
                 }
              })

      }
      function changePass(){
          var newPass = $('#newPass').val();
          if(newPass==''){
              alert('请输入新密码');
          }else{
              $.ajax({
                      url: 'api/user.php',
                      type: 'GET',
                      data: {
                          'action' : 'changePass',
                          'newPass' : newPass,
                      }
                  })
                  .done(function(data){
                      if(data == 1){
                         alert('修改成功');
                          changePassDivHide();
                      }
                  })
          }

      }
      function changePassDivShow(){
          $('.changePassDiv').fadeIn(300);

      }
      function changePassDivHide(){
          $('.changePassDiv').fadeOut(300);
      }

      function pageMani(action){
          if(action == 0){
              page--;
          }else if( action == 1 ){
              page++;
          }else{
              page=1;
          }
          $('#page-current').html(page);
      }

  </script>
  </body>
</html>
